use sqlx::MySqlPool;
use std::env;

pub async fn init_db() -> Result<MySqlPool, sqlx::Error> {
    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");

    let pool = MySqlPool::connect(&database_url).await?;

    // 测试连接
    pool.acquire().await?;
    println!("✅ 数据库连接成功");

    Ok(pool)
}